class FundsController < ApplicationController
  def show
    @report = MorningStarReport.recent
    order_criteria = params[:order] || "code"
    direction = params[:direction] || "ASC"
    @report.order(order_criteria.to_sym, direction.to_sym) rescue nil
    @highlights = session[:highlights] || []
  end
  
  def click
    code = params[:code]
    @highlights = session[:highlights] || []
    toggle_highlight code if code
    session[:highlights] = @highlights
    render :partial => "fund" , :locals => {:fund => MorningStarReport.recent.find_fund_by_code(code)}
  end

  private
  def toggle_highlight(code)
    unless @highlights.include? code
      @highlights << code 
    else
      @highlights.delete(code)
    end
  end  
end
